import numpy as np
import pandas as pd

def generate_heart_parameters_from_df(df):
    """
    批量生成心输出量参数，输入人口学DataFrame，输出带id的心参数DataFrame。
    """
    results = []
    for idx, row in df.iterrows():
        person_id = row.get('id', idx)
        bsa = row.get('bsa', None)
        age = row.get('age', None)
        if bsa is None or age is None:
            continue
        cardiac_output = bsa * (183.59 + (110.87 * (np.exp(-0.0797 * age) - np.exp(-0.716 * age))))
        results.append({
            'id': person_id,
            'Heart_cardiac_output': cardiac_output
        })
    return pd.DataFrame(results)

if __name__ == "__main__":
    # 构造测试数据
    test_df = pd.DataFrame({
        'id': [1, 2],
        'bsa': [1.7, 1.8],
        'age': [30, 40]
    })
    result = generate_heart_parameters_from_df(test_df)
    print(result)
